package com.example.game_app

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import com.example.game.sdk.framework.GameApiCallback
import com.example.game.sdk.framework.GameSdkActivity
import com.example.game.sdk.framework.plugin.channel.GSDKChannel
import org.json.JSONObject

private const val TAG = "MainActivity"

class MainActivity : GameSdkActivity(), View.OnClickListener {
    private lateinit var btnLogin: Button
    private lateinit var btnLogout: Button
    private lateinit var btnPay: Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.game_main_activity)
        btnLogin = findViewById<Button>(R.id.btn_login)
        btnLogout = findViewById<Button>(R.id.btn_logout)
        btnPay = findViewById<Button>(R.id.btn_pay)
        btnLogin.setOnClickListener(this)
        btnLogout.setOnClickListener(this)
        btnPay.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        if (v == btnLogin) {
            GSDKChannel.login(object : GameApiCallback {
                override fun onResult(
                    code: Int,
                    message: String,
                    data: JSONObject
                ) {
                    Log.d(TAG, "onResult: code=$code, message=$message, data=$data")
                }
            })
        } else if (v == btnLogout) {
            GSDKChannel.logout(object : GameApiCallback {
                override fun onResult(
                    code: Int,
                    message: String,
                    data: JSONObject
                ) {
                    Log.d(TAG, "onResult: code=$code, message=$message, data=$data")
                }
            })
        } else if (v == btnPay) {
            GSDKChannel.pay(JSONObject(), object : GameApiCallback {
                override fun onResult(
                    code: Int,
                    message: String,
                    data: JSONObject
                ) {
                    Log.d(TAG, "onResult: code=$code, message=$message, data=$data")
                }
            })
        }
    }
}